package ru.acme.lab12.domain.account;


abstract public class AbstractAccount implements Account {
	
	private double balance = 0;
	
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Double.valueOf(balance).hashCode();
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbstractAccount other = (AbstractAccount) obj;
		if (balance != other.balance)
			return false;
		return true;
	}

	public String toString() {
		return "balance=" + balance;
	}

	public double getBalance() {
		return balance;
	}
	
	public void deposit(double amount) {
		balance += amount;
	}
	
	public boolean withdraw(double amount) {
		if (balance >= amount) {
			balance -= amount;
			return true;
		}
		return false;
	}
	
	public AbstractAccount(double balance) {
		this.balance = balance;
	}

	public double maximumAmountToWihdraw() {
		return balance;
	}
	
	public long decimalValue() {
		return Math.round(balance);
	}
}
